<?php
require_once('connections/Infinitus.php');

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO infinitus_campannas (titulo, pais, minombre, micorreo, url_redirigir_suscribir,url_redirigir_suscribir_error,url_enlace_afiliados, niveles, smtp_servidor, smtp_puerto, smtp_usuario, smtp_clave, smtp_usar_ssl,asunto_correo_inicial, html_correo_inicial) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s)",
                       GetSQLValueString($_POST['titulo'], "text"),
                       GetSQLValueString($_POST['pais'], "text"),
                       GetSQLValueString($_POST['minombre'], "text"),
                       GetSQLValueString($_POST['micorreo'], "text"),
                       GetSQLValueString($_POST['url_redirigir_suscribir'], "text"),
                       GetSQLValueString($_POST['url_redirigir_suscribir_error'], "text"),
                       GetSQLValueString($_POST['url_enlace_afiliados'], "text"),
                       GetSQLValueString($_POST['niveles'], "int"),
                       GetSQLValueString($_POST['smtp_servidor'], "text"),
                       GetSQLValueString($_POST['smtp_puerto'], "text"),
                       GetSQLValueString($_POST['smtp_usuario'], "text"),
                       GetSQLValueString($_POST['smtp_clave'], "text"),
                       GetSQLValueString($_POST['smtp_usar_ssl'], "int"),
                       GetSQLValueString($_POST['asunto_correo_inicial'], "text"),
                       GetSQLValueString($_POST['html_correo_inicial'], "text"));

  mysql_select_db($database_Infinitus, $Infinitus);
  $Result1 = mysql_query($insertSQL, $Infinitus) or die(mysql_error());

  $insertGoTo = "campannas_listado_vista.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table width="500" align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Titulo:</td>
      <td><input type="text" name="titulo" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Pais:</td>
      <td><input type="text" name="pais" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Minombre:</td>
      <td><input type="text" name="minombre" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Micorreo:</td>
      <td><input type="text" name="micorreo" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Url_redirigir_suscribir:</td>
      <td><input type="text" name="url_redirigir_suscribir" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Url_redirigir_error</td>
      <td><input type="text" name="url_redirigir_suscribir_error" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Url enlace afiliados</td>
      <td><input type="text" name="url_enlace_afiliados" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Niveles:</td>
      <td><input type="text" name="niveles" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Smtp_servidor:</td>
      <td><input type="text" name="smtp_servidor" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Smtp_puerto:</td>
      <td><input type="text" name="smtp_puerto" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Smtp_usuario:</td>
      <td><input type="text" name="smtp_usuario" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Smtp_clave:</td>
      <td><input type="text" name="smtp_clave" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Smtp_usar_ssl:</td>
      <td><input type="text" name="smtp_usar_ssl" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><p>Asunto Correo inicial al</p>
      <p>suscribirse:</p></td>
      <td><input name="asunto_correo_inicial" type="text" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"><p>Mensaje Correo inicial al</p>
      <p>suscribirse:</p></td>
      <td><textarea name="html_correo_inicial" cols="32" rows="5"></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Ingresar Respondedor" />
      <a href="campannas_listado.php" target="_self">Cancelar</a></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
